#!/bin/sh -e

bash_maj=${2%%.*}
bash_min=${2%.p*} bash_min=${bash_min#"$bash_maj."}
for patch in "bash$bash_maj$bash_min-"0??; do
    [ -f "$patch" ] && patch -p0 < "$patch"
done

./configure \
    --prefix=/usr \
    --without-bash-malloc \
    --disable-nls

export MAKEFLAGS="TERMCAP_LIB=/usr/lib/libncursesw.a $MAKEFLAGS"

make
make DESTDIR="$1" install

ln -s bash "$1/usr/bin/sh"

# Remove bash C header files. I couldn't find an actual example of how these
# can be useful to someone. If you can think of one, and do need it, send me a
# mail and I will think about adding them back if it makes sense to me.
# Otherwise, you can remove this part through a hook or a fork.
rm -rf "$1/usr/include"
